package com.wangdao.wechatmall.service.wx;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wangdao.wechatmall.bean.bo.wx.BrandListBO;
import com.wangdao.wechatmall.bean.pojo.Brand;
import com.wangdao.wechatmall.bean.pojo.BrandExample;
import com.wangdao.wechatmall.bean.vo.wx.BrandDetailVO;
import com.wangdao.wechatmall.bean.vo.wx.BrandListVO;
import com.wangdao.wechatmall.mapper.BrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: JK
 * @Date: create in 2021/7/12 11:49
 */
@Service
public class WXBrandServiceImpl implements WXBrandService {
    @Autowired
    BrandMapper brandMapper;

    @Override
    public BrandListVO queryBrandList(BrandListBO brandListBO) {
        PageHelper.startPage(brandListBO.getPage(), brandListBO.getSize());

        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria brandExampleCriteria = brandExample.createCriteria();
        brandExampleCriteria.andDeletedEqualTo(0);
        List<Brand> brands = brandMapper.selectByExample(brandExample);
        ArrayList<BrandListVO.BrandListDTO> brandListDTOS = new ArrayList<>();
        for (Brand brand : brands) {
            BrandListVO.BrandListDTO brandListDTO = new BrandListVO.BrandListDTO(brand.getId(), brand.getName(), brand.getDesc(), brand.getPicUrl(), brand.getFloorPrice());
            brandListDTOS.add(brandListDTO);
        }


        BrandListVO brandListVO = new BrandListVO();
        brandListVO.setBrandList(brandListDTOS);
        PageInfo<Brand> brandPageInfo = new PageInfo<>(brands);
        int pages = brandPageInfo.getPages();
        brandListVO.setTotalPages(pages);

        return brandListVO;
    }

    @Override
    public BrandDetailVO queryBrandDetail(Integer id) {
        Brand brand = brandMapper.selectByPrimaryKey(id);
        BrandDetailVO brandDetailVO = new BrandDetailVO();
        brandDetailVO.setBrand(brand);
        return brandDetailVO;
    }
}
